package server

import (
	"github.com/urfave/cli/v2"
	"log"
	"os"
	"runtime"
)

func Menu() {
	//默认并发数
	numCPU := runtime.NumCPU()
	app := &cli.App{
		Name:  "GoLanf Downloader",
		Usage: "文件并发下载器",
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     "url",
				Aliases:  []string{"u"},
				Usage:    "下载的 `URL`",
				Required: true,
			},
			&cli.StringFlag{
				Name:    "output",
				Aliases: []string{"o"},
				Usage:   "输出文件名 `filename`",
			},
			&cli.IntFlag{
				Name:    "concurrency",
				Aliases: []string{"n"},
				Value:   numCPU,
				Usage:   "并发下载数量 `number`",
			},
			&cli.BoolFlag{
				Name:    "resume",
				Aliases: []string{"r"},
				Value:   true,
				Usage:   "继续下载 download",
			},
		},
		Action: func(c *cli.Context) error {
			strUrl := c.String("url")
			filename := c.String("output")
			concurrency := c.Int("concurrency")
			resume := c.Bool("resume")

			return NewDownloader(concurrency, resume).Dowmload(strUrl, filename)
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}

}
